<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- /fasttmp/mkdist-qt-4.3.5-1211793125/qtopia-core-opensource-src-4.3.5/src/gui/kernel/qsound.cpp -->
<head>
  <title>Qt 4.3: QSound Class Reference</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
<td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">QSound Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1>
<p>The QSound class provides access to the platform audio facilities. <a href="#details">More...</a></p>
<pre> #include &lt;QSound&gt;</pre><p>Inherits <a href="qobject.html">QObject</a>.</p>
<ul>
<li><a href="qsound-members.html">List of all members, including inherited members</a></li>
<li><a href="qsound-qt3.html">Qt 3 support members</a></li>
</ul>
<a name="public-functions"></a>
<h3>Public Functions</h3>
<ul>
<li><div class="fn"/><b><a href="qsound.html#QSound">QSound</a></b> ( const QString &amp; <i>filename</i>, QObject * <i>parent</i> = 0 )</li>
<li><div class="fn"/><b><a href="qsound.html#dtor.QSound">~QSound</a></b> ()</li>
<li><div class="fn"/>QString <b><a href="qsound.html#fileName">fileName</a></b> () const</li>
<li><div class="fn"/>bool <b><a href="qsound.html#isFinished">isFinished</a></b> () const</li>
<li><div class="fn"/>int <b><a href="qsound.html#loops">loops</a></b> () const</li>
<li><div class="fn"/>int <b><a href="qsound.html#loopsRemaining">loopsRemaining</a></b> () const</li>
<li><div class="fn"/>void <b><a href="qsound.html#setLoops">setLoops</a></b> ( int <i>number</i> )</li>
</ul>
<ul>
<li><div class="fn"/>29 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
</ul>
<a name="public-slots"></a>
<h3>Public Slots</h3>
<ul>
<li><div class="fn"/>void <b><a href="qsound.html#play-2">play</a></b> ()</li>
<li><div class="fn"/>void <b><a href="qsound.html#stop">stop</a></b> ()</li>
</ul>
<ul>
<li><div class="fn"/>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
</ul>
<a name="static-public-members"></a>
<h3>Static Public Members</h3>
<ul>
<li><div class="fn"/>bool <b><a href="qsound.html#isAvailable">isAvailable</a></b> ()</li>
<li><div class="fn"/>void <b><a href="qsound.html#play">play</a></b> ( const QString &amp; <i>filename</i> )</li>
</ul>
<ul>
<li><div class="fn"/>5 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
</ul>
<h3>Additional Inherited Members</h3>
<ul>
<li><div class="fn"/>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
<li><div class="fn"/>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
<li><div class="fn"/>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
</ul>
<a name="details"></a>
<hr />
<h2>Detailed Description</h2>
<p>The QSound class provides access to the platform audio facilities.</p>
<p>Qt provides the most commonly required audio operation in GUI applications: asynchronously playing a sound file. This is most easily accomplished using the static <a href="qsound.html#play">play</a>() function:</p>
<pre> QSound::play(&quot;mysounds/bells.wav&quot;);</pre>
<p>Alternatively, create a QSound object from the sound file first and then call the <a href="qsound.html#play">play</a>() slot:</p>
<pre> QSound bells(&quot;mysounds/bells.wav&quot;);
 bells.play();</pre>
<p>Once created a QSound object can be queried for its <a href="qsound.html#fileName">fileName</a>() and total number of <a href="qsound.html#loops">loops</a>() (i.e&#x2e; the number of times the sound will play). The number of repetitions can be altered using the <a href="qsound.html#setLoops">setLoops</a>() function. While playing the sound, the <a href="qsound.html#loopsRemaining">loopsRemaining</a>() function returns the remaining number of repetitions. Use the <a href="qsound.html#isFinished">isFinished</a>() function to determine whether the sound has finished playing.</p>
<p>Sounds played using a QSound object may use more memory than the static <a href="qsound.html#play">play</a>() function, but it may also play more immediately (depending on the underlying platform audio facilities). Use the static <a href="qsound.html#isAvailable">isAvailable</a>() function to determine whether sound facilities exist on the platform. Which facilities that are actually used varies:</p>
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
<thead><tr valign="top" class="qt-style"><th>Platform</th><th>Audio Facility</th></tr></thead>
<tr valign="top" class="odd"><td>Microsoft Windows</td><td>The underlying multimedia system is used; only WAVE format sound files are supported.</td></tr>
<tr valign="top" class="even"><td>X11</td><td>The <a href="ftp://ftp.x.org/contrib/audio/nas/">Network Audio System</a> is used if available, otherwise all operations work silently. NAS supports WAVE and AU files.</td></tr>
<tr valign="top" class="odd"><td>Mac OS X</td><td>NSSound is used. All formats that NSSound supports, including QuickTime formats, are supported by Qt/Mac.</td></tr>
<tr valign="top" class="even"><td>Qtopia Core</td><td>A built-in mixing sound server is used, accessing <tt>/dev/dsp</tt> directly. Only the WAVE format is supported.</td></tr>
</table></p>
<p>Note that QSound does not support <a href="resources.html">resources</a>. This might be fixed in a future Qt version.</p>
<hr />
<h2>Member Function Documentation</h2>
<h3 class="fn"><a name="QSound"></a>QSound::QSound ( const <a href="qstring.html">QString</a> &amp; <i>filename</i>, <a href="qobject.html">QObject</a> * <i>parent</i> = 0 )</h3>
<p>Constructs a <a href="qsound.html">QSound</a> object from the file specified by the given <i>filename</i> and with the given <i>parent</i>.</p>
<p>This may use more memory than the static <a href="qsound.html#play">play</a>() function, but it may also play more immediately (depending on the underlying platform audio facilities).</p>
<p>See also <a href="qsound.html#play">play</a>().</p>
<h3 class="fn"><a name="dtor.QSound"></a>QSound::~QSound ()</h3>
<p>Destroys this sound object. If the sound is not finished playing, the <a href="qsound.html#stop">stop</a>() function is called before the sound object is destructed.</p>
<p>See also <a href="qsound.html#stop">stop</a>() and <a href="qsound.html#isFinished">isFinished</a>().</p>
<h3 class="fn"><a name="fileName"></a><a href="qstring.html">QString</a> QSound::fileName () const</h3>
<p>Returns the filename associated with this <a href="qsound.html">QSound</a> object.</p>
<p>See also <a href="qsound.html#QSound">QSound</a>().</p>
<h3 class="fn"><a name="isAvailable"></a>bool QSound::isAvailable ()&nbsp;&nbsp;<tt> [static]</tt></h3>
<p>Returns true if sound facilities exist on the platform; otherwise returns false.</p>
<p>If no sound is available, all <a href="qsound.html">QSound</a> operations work silently and quickly. An application may choose either to notify the user if sound is crucial to the application or to operate silently without bothering the user.</p>
<p>Note: On Windows this always returns true because some sound card drivers do not implement a way to find out whether it is available or not.</p>
<h3 class="fn"><a name="isFinished"></a>bool QSound::isFinished () const</h3>
<p>Returns true if the sound has finished playing; otherwise returns false.</p>
<p><b>Warning:</b> On Windows this function always returns true for unlooped sounds.</p>
<h3 class="fn"><a name="loops"></a>int QSound::loops () const</h3>
<p>Returns the number of times the sound will play.</p>
<p>See also <a href="qsound.html#loopsRemaining">loopsRemaining</a>() and <a href="qsound.html#setLoops">setLoops</a>().</p>
<h3 class="fn"><a name="loopsRemaining"></a>int QSound::loopsRemaining () const</h3>
<p>Returns the remaining number of times the sound will loop (this value decreases each time the sound is played).</p>
<p>See also <a href="qsound.html#loops">loops</a>() and <a href="qsound.html#isFinished">isFinished</a>().</p>
<h3 class="fn"><a name="play"></a>void QSound::play ( const <a href="qstring.html">QString</a> &amp; <i>filename</i> )&nbsp;&nbsp;<tt> [static]</tt></h3>
<p>Plays the sound stored in the file specified by the given <i>filename</i>.</p>
<p>See also <a href="qsound.html#stop">stop</a>(), <a href="qsound.html#loopsRemaining">loopsRemaining</a>(), and <a href="qsound.html#isFinished">isFinished</a>().</p>
<h3 class="fn"><a name="play-2"></a>void QSound::play ()&nbsp;&nbsp;<tt> [slot]</tt></h3>
<p>This is an overloaded member function, provided for convenience.</p>
<p>Starts playing the sound specified by this <a href="qsound.html">QSound</a> object.</p>
<p>The function returns immediately. Depending on the platform audio facilities, other sounds may stop or be mixed with the new sound. The sound can be played again at any time, possibly mixing or replacing previous plays of the sound.</p>
<p>See also <a href="qsound.html#fileName">fileName</a>().</p>
<h3 class="fn"><a name="setLoops"></a>void QSound::setLoops ( int <i>number</i> )</h3>
<p>Sets the sound to repeat the given <i>number</i> of times when it is played.</p>
<p>Note that passing the value -1 will cause the sound to loop indefinitely.</p>
<p>See also <a href="qsound.html#loops">loops</a>().</p>
<h3 class="fn"><a name="stop"></a>void QSound::stop ()&nbsp;&nbsp;<tt> [slot]</tt></h3>
<p>Stops the sound playing.</p>
<p>Note that on Windows the current loop will finish if a sound is played in a loop.</p>
<p>See also <a href="qsound.html#play">play</a>().</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%">Copyright &copy; 2008 <a href="trolltech.html">Trolltech</a></td>
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="30%" align="right"><div align="right">Qt 4.3.5</div></td>
</tr></table></div></address></body>
</html>
